home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Atari Mega Archive 1
/
Atari Mega Archive - Volume 1.iso
/
printing
/
techpp.arc
/
PSCONV.C
< prev
next >
Wrap
Text File
|
1985-11-20
|
2KB
|
70 lines
/* XmodToPs -Translate (Fortran) xmodem file into c text file; wrap lines
that exceed 100 chars
This version includes a file HEADER.PS (if it exists) following the first
^D */
#include stdio
#include ctype
main()
{
int ch, eofs, len, wrap;
char header[128], fname[128];
FILE *in, *out, *hdr;
printf( "Input file? " );
gets( fname );
if( (in = fopen( fname, "r" )) == NULL )
{
printf( "Unable to open input file: %s\n", fname );
exit();
}
printf( "Output file? " );
gets( fname );
if( (out = fopen( fname, "w" )) == NULL )
{
printf( "Unable to open output file: %s\n", fname );
exit();
}
eofs = len = wrap = 0;
while( (ch = fgetc( in )) != EOF )
if( ch == '\r' || ch == '\n' )
{
fputc( '\n', out );
len = wrap = 0;
}
else if( ch == '\0' ) continue;
else if( (ch == '\004') && (++eofs < 2) )
{ /* ^D = PS EOF */
fprintf( out, "\004\n" );
len = wrap = 0;
if( (hdr = fopen( "header.ps", "r" )) != NULL )
{
while( fgets( header, 128, hdr ) != NULL )
fputs( header, out );
fclose( hdr );
}
}
else if( isspace( ch ) )
{
if( ++len > 80 ) wrap = TRUE;
if( wrap )
{
fputc( '\n', out );
len = wrap = 0;
}
else fputc( ch, out );
}
else
{
fputc( ch, out );
if( len == 127 )
{
fputc( '\n', out );
len = wrap = 0;
}
else if( ++len > 80 ) wrap = TRUE;
}
fclose( in );
fclose( out );
} /* main */
əəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəəə